package org.lvgo;

import org.lvgo.singleton.enumsingleton.EnumIvoryTower;
import org.lvgo.singleton.immediately.StraightwaySingleton;
import org.lvgo.singleton.lazy.DoubleCheckLockingSingleton;
import org.lvgo.singleton.lazy.InternalClassSingleton;
import org.lvgo.singleton.lazy.LazyLoadingSingleton1;
import org.lvgo.singleton.lazy.LazyLoadingSingleton2;

/**
 * singleton
 * @author lvgo
 */
public class App {

    public static void main(String[] args) {

        // 枚举类
        EnumIvoryTower enumlvoryTower1 = EnumIvoryTower.INSTANCE;
        EnumIvoryTower enumlvoryTower2 = EnumIvoryTower.INSTANCE;

        System.out.println("enumlvoryTower1 = " + enumlvoryTower1);
        System.out.println("enumlvoryTower2 = " + enumlvoryTower2);

        System.out.println();

        // 饿汉式单例
        StraightwaySingleton straightwaySingleton1 = StraightwaySingleton.getInstance();
        StraightwaySingleton straightwaySingleton2 = StraightwaySingleton.getInstance();

        System.out.println("straightwaySingleton1 = " + straightwaySingleton1);
        System.out.println("straightwaySingleton2 = " + straightwaySingleton2);

        System.out.println();

        // 内部类单例
        InternalClassSingleton internalClassSingleton1 = InternalClassSingleton.getInstance();
        InternalClassSingleton internalClassSingleton2 = InternalClassSingleton.getInstance();

        System.out.println("internalClassSingleton1 = " + internalClassSingleton1);
        System.out.println("internalClassSingleton2 = " + internalClassSingleton2);

        System.out.println();

        // 懒加载单例1
        LazyLoadingSingleton1 lazyLoadingSingleton11 = LazyLoadingSingleton1.getInstance();
        LazyLoadingSingleton1 lazyLoadingSingleton12 = LazyLoadingSingleton1.getInstance();

        System.out.println("lazyLoadingSingleton11 = " + lazyLoadingSingleton11);
        System.out.println("lazyLoadingSingleton12 = " + lazyLoadingSingleton12);

        System.out.println();

        // 懒加载单例2
        LazyLoadingSingleton2 lazyLoadingSingleton21 = LazyLoadingSingleton2.getInstance();
        LazyLoadingSingleton2 lazyLoadingSingleton22 = LazyLoadingSingleton2.getInstance();

        System.out.println("lazyLoadingSingleton21 = " + lazyLoadingSingleton21);
        System.out.println("lazyLoadingSingleton22 = " + lazyLoadingSingleton22);

        System.out.println();

        // 双重锁单例
        DoubleCheckLockingSingleton doubleCheckLockingSingleton1 = DoubleCheckLockingSingleton.getInstance();
        DoubleCheckLockingSingleton doubleCheckLockingSingleton2 = DoubleCheckLockingSingleton.getInstance();

        System.out.println("doubleCheckLockingSingleton1 = " + doubleCheckLockingSingleton1);
        System.out.println("doubleCheckLockingSingleton2 = " + doubleCheckLockingSingleton2);

        System.out.println();
    }

}
